flowerknightfandomcom-20200223-history
User blog:Definitelydrunk/Gathering FKG Assets
Intro So, if you've ever tried looking into pulling assets for a lot of online clicker games such as FKG, you've proably noticed that in most cases, so long as you open up dev tools and watch urls in the network waterfall you are served straight up assets for any image you would want to copy out and share somewhere. In other cases, you can check your browser cache or the page resources and find anything you want. Unfortunately, while FKG does do these same things, there's a trick applied. Namely, that the resources have all bin compressed using zlib and their filenames obfuscated. This makes remembering the url of the file server and statically replacing some strings trickier for anyone looking to grab all the assets en masse. This short post will not show you how to get around deciphering the file names (as I do not know how to do that yet), but it will give you an easy way to just play FKG and click around the interface while also being able to save all the image and sound assets streamed to your computer. The Process When you begin playing FKG, you should open dev tools by pressing f12 or ctrl+shift+i (option+command+i for mac users). Some browsers use different combinations, but these combos should open it up for the big two browsers (Firefox, Chrome). A frame will open up somewhere within the browser and look something like this: Click the Network tab as highlighted in the previous picture and watch as all the network traffic interacting with your browser is recorded. This is what you want. Feel free to click around the user interface, but if your main goal is to get some of those voice lines and images, I would head towards the reference library in the office. So just click around, listen to the voice lines you wanna hear, click to get all the pictures you wanna see and then right click on the network waterfall and select the option to "Save as HAR with Content" or "Copy All as HAR". As seen here: The Script So, you recorded all your browser traffic for your FKG tab and saved this mysterious HAR file. What to do with this file that you just created? Simple, you run this python script against it and watch it download all the assets for you. #!/usr/bin/python3 ########################################################################### # usage: fkg_har_asset_grabber.py -h har_file # # Parses a HAR file for FKG assets and downloads them out of Cloudfront # # positional arguments: # har_file HAR file to parse # # optional arguments: # -h, --help show this help message and exit ############################################################################ import argparse import json import requests import traceback import zlib supported_types = 'voice' tried_urls = {} def write_image(asset_url): response = requests.get(asset_url) f = open('{}.{}'.format(asset_url.split('/')-1.split('?')0, 'png'), 'wb') f.write(zlib.decompress(response.content)) f.close tried_urlsasset_url = 1 def write_audio(asset_url): response = requests.get(asset_url) f = open('{}_{}.{}'.format(asset_url.split('/')-2, asset_url.split('/')-1.split('?')0, 'mp3'), 'wb') f.write(zlib.decompress(response.content)) f.close tried_urlsasset_url = 1 def download_asset(asset_url, asset_type): if asset_url in tried_urls.keys(): return try: if asset_type 'images': write_image(asset_url) else: write_audio(asset_url) except: print('Error grabbing asset: {}\n{}'.format(asset_url, traceback.format_exc())) def main(): parser = argparse.ArgumentParser(description='Parses a HAR file for FKG assets and downloads them out of Cloudfront', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('har_file', type=str, help='HAR file to parse') args = parser.parse_args() har_content = json.load(open(args.har_file, 'r')) for entry in har_content'log''entries': for atype in supported_types: if atype in entry'request''url': download_asset(entry'request''url', atype) if __name__ '__main__': main() You may be wondering how to get this thing to work. What you need to do is go download the python version 3 interpreter here: https://www.python.org/downloads/Well, getting python to work is another matter in and of itself, but if you have specifc questions about getting it to work you can leave me a comment on my message wall. Otherwise, enjoy grabbing assets! Category:Blog posts